import { defineConfig } from 'vitepress'
import type { MarkdownRenderer } from 'vitepress'
import { withPwa } from '@vite-pwa/vitepress'

// // md 添加自定义属性
function MdCustomAttrPugin(md: MarkdownRenderer, type: string, mdOptions: object) {
  const defaultRenderer = md.renderer.rules[type]

  if (defaultRenderer) {
    md.renderer.rules[type] = (tokens, idx, options, env, self) => {
      const token = tokens[idx]
      if (mdOptions) {
        for (let i in mdOptions) {
          token.attrSet(i, mdOptions[i])
        }
      }
      return defaultRenderer(tokens, idx, options, env, self)
    }
  }
}

// export default defineConfig({
//   title: "My Awesome Project",
//   description: "A VitePress Site",
//   themeConfig: {
//     nav: [
//       { text: 'Home', link: '/' },
//       { text: 'Examples', link: '/markdown-examples' }
//     ],

//     sidebar: [
//       {
//         text: 'Examples',
//         items: [
//           { text: 'Markdown Examples', link: '/markdown-examples' },
//           { text: 'Runtime API Examples', link: '/api-examples' }
//         ]
//       }
//     ],

//     socialLinks: [
//       { icon: 'github', link: 'https://github.com/vuejs/vitepress' }
//     ]
//   }
// })


// https://vitepress.dev/reference/site-config
export default withPwa(
  defineConfig({
    markdown: {
      // 显示行号
      lineNumbers: true,
      // 使用主题
      theme: 'material-theme-palenight',
      // md 配置
      config: (md) => {
        // 大图预览插件配置
        md.use(MdCustomAttrPugin, 'image', { 'data-fancybox': 'gallery' })
      },
    },
    lang: 'zh-CN',
    base: '/scroll-kings-notes/',   // 部署的路径配置
    title: '王遂杨卷死你哼！',
    titleTemplate: '( •̀ ω •́ )✧',
    description: '王遂杨的卷王日常',
    cleanUrls: true,
    head: [
      [
        'link',
        {
          rel: 'icon',
          href: '/wsy.ico',
        },
      ],
      // 大图预览插件资源
      [
        'link',
        { rel: 'stylesheet', href: 'https://cdn.jsdelivr.net/npm/@fancyapps/ui/dist/fancybox.css' },
      ],
      ['script', { src: 'https://cdn.jsdelivr.net/npm/@fancyapps/ui@4.0/dist/fancybox.umd.js' }],
    ],
    // lastUpdated: true,
    themeConfig: {
      logo: '/wsy.png',
      siteTitle: '天不生我王遂杨卷道万古如长夜',
      returnToTopLabel: '返回顶部',
      search: {
        provider: 'local',
        options: {
          translations: {
            button: {
              buttonText: '搜索文档',
              buttonAriaLabel: '搜索文档',
            },
            modal: {
              displayDetails: '展开详情',
              noResultsText: '无法找到相关结果',
              resetButtonTitle: '清除查询条件',

              footer: {
                selectText: '选择',
                navigateText: '切换',
              },
            },
          },
        },
      },
      outline: {
        label: '目录',
        level: 'deep',
      },
      docFooter: {
        prev: '上一篇',
        next: '下一篇',
      },
      footer: {
        message: '根据 MIT 许可证发布',
        copyright: ` Copyright © 2023-${new Date().getFullYear()} YPS`,
        // message: '吉ICP备2023010479号-1',
        // copyright: `根据 MIT 许可证发布 Copyright © 2023-${new Date().getFullYear()} YPS`,
      },
      // https://vitepress.dev/reference/default-theme-config
      // editLink: {
      //   pattern: 'https://gitee.com/Megasu/uni-app-shop-note/edit/master/:path',
      //   text: '写的什么',
      // },
      // lastUpdatedText: '最近更新',

      nav: [
        {
          text: '卷王笔记ヾ(•ω•`)o',
          items: [
            { text: 'java', link: '/java/javase/' },
            { text: 'web', link: '/web/vue3/' },
            { text: '扩展知识点', link: '/others/rxjava/' },
            { text: '数据结构与算法', link: '/suanfa/binarySearch/' },
            { text: '个人总结', link: '/summary/mei-kuang/' },
          ],
        },
        {
          text: '卷王项目(￣o￣).zZ', link: '/project/cangqiong/',
        },
      ],


      sidebar: {
        '/java/': [
          {
            text: 'Java',
            collapsed: false,
            items: [
              { text: 'JavaSE', link: '/java/javase/' },
              { text: 'JavaWeb', link: '/java/javaweb/' },
            ],
          },
          {
            text: '多线程',
            collapsed: false,
            items: [
              { text: '多线程', link: '/java/multithreading/' },
              { text: '多线程基础', link: '/java/multithreading/1' },
              { text: '多线程略微高级一点点', link: '/java/multithreading/2' },
              { text: '多线程扩展', link: '/java/multithreading/3' },
            ],
          },
          {
            text: 'SpringCloud',
            collapsed: false,
            items: [
              { text: 'Mybatisplus', link: '/java/mybatisplus/' },
              { text: 'Docker', link: '/java/docker/' },
              { text: 'Docker镜像安装', link: '/java/docker/install' },
              { text: 'Nacos', link: '/java/wservice/nacos' },
              { text: 'openfeign', link: '/java/wservice/openfeign' },
              { text: 'gateway', link: '/java/wservice/gateway' },
              { text: '服务保护', link: '/java/wservice/baohu' },
              { text: 'RabbitMQ', link: '/java/rabbitmq/' },
              { text: 'Elasticsearch', link: '/java/elasticsearch/' },
            ],
          },
        ],
        '/web/': [
          {
            text: '前端',
            collapsed: false,
            items: [
              { text: 'Vue3', link: '/web/vue3/' },
              { text: '小程序', link: '/web/xcx/' },
              { text: 'VueUse', link: '/web/vueuse/' },
              { text: 'Pina', link: '/web/pinia/' },
            ],
          },
        ],
        '/others/': [
          {
            text: '扩展知识点',
            items: [
              { text: 'RxJava响应式编程', link: '/others/rxjava/' },
              { text: 'SSE通讯方案', link: '/others/sse/' },
              { text: '分库分表', link: '/others/share-database/' },
              { text: '幂等性设计', link: '/others/mi-deng-xing/' },
              { text: '线程池隔离', link: '/others/xian-cheng-chi-ge-li/' },
            ],
          },
        ],
        '/suanfa/': [
          {
            text: '数据结构与算法',
            collapsed: false,
            items: [
              { text: '二分查找', link: '/suanfa/binarySearch/' },
            ],
          },
        ],
        '/summary/': [
          {
            text: '总结',
            collapsed: false,
            items: [
              { text: '煤矿项目总结', link: '/summary/mei-kuang/' },
            ],
          },
        ],
        '/project/': [
          {
            text: '项目',
            collapsed: false,
            items: [
              { text: '苍穹外卖', link: '/project/cangqiong/' },
              { text: '红包雨', link: '/project/hongbaoyu/' },
              { text: '尚上优选', link: '/project/shangshangyouxuan/' },
            ],
          },
          {
            text: '尚品甄选',
            collapsed: false,
            items: [
              { text: '商品甄选', link: '/project/shangpinzhenxuan/' },
              { text: '商品甄选-日志记录', link: '/project/shangpinzhenxuan/log' },
              { text: '商品甄选-支付宝', link: '/project/shangpinzhenxuan/pay' },
              { text: '商品甄选-部署', link: '/project/shangpinzhenxuan/deploy' },
            ],
          },
          {
            text: '乐尚代驾',
            collapsed: false,
            items: [
              { text: '乐尚代驾', link: '/project/leshangdaijia/' },
              { text: '乐尚代驾-规则引擎', link: '/project/leshangdaijia/drools' },
              { text: '乐尚代驾-腾讯云API', link: '/project/leshangdaijia/tengxunyun' },
              { text: '乐尚代驾-XXL-job', link: '/project/leshangdaijia/xxl-job' },
              { text: '乐尚代驾-锁', link: '/project/leshangdaijia/lock' },
              { text: '乐尚代驾-分布式事务', link: '/project/leshangdaijia/seata' },
              { text: '乐尚代驾-MongoDB', link: '/project/leshangdaijia/mongodb' },
              { text: '乐尚代驾-Minio', link: '/project/leshangdaijia/minio' },
              { text: '乐尚代驾-RabbitMQ', link: '/project/leshangdaijia/rabbitmq' },
              { text: '乐尚代驾-超时订单取消', link: '/project/leshangdaijia/chaoshidingdanquxiao' },
            ],
          },
        ],
      },

      socialLinks: [
        {
          icon: {
            svg: '<svg t="1708159775126" class="icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="10613" width="200" height="200"><path d="M669.3 369.4c9.8 0 19.6 0 29.4 1.6C671 245.2 536.9 152 383.2 152 211.6 152 71 269.7 71 416.8c0 85 45.8 156.9 124.2 210.9l-31.1 93.2L273.6 667c39.2 8.2 70.3 16.3 109.5 16.3 9.8 0 19.6 0 31.1-1.6-6.5-21.3-9.8-42.5-9.8-65.4 0.1-135.7 116.2-246.9 264.9-246.9z m-168.4-85c24.5 0 39.2 16.3 39.2 39.2 0 22.9-16.3 39.2-39.2 39.2-24.5 0-47.4-16.4-47.4-39.2 0-24.5 24.6-39.2 47.4-39.2z m-216.3 73.1c-24.7 0-47.8-16.2-47.8-38.8 0-24.3 24.7-38.8 47.8-38.8s39.5 16.2 39.5 38.8c0.1 22.7-16.4 38.8-39.5 38.8z" fill="#24DB5A" p-id="10614"></path><path d="M953.8 613c0-125.9-124.2-227.2-264.8-227.2-148.8 0-266.5 103-266.5 227.2 0 125.9 117.7 227.2 266.5 227.2 31.1 0 62.1-8.2 93.2-16.3l85 47.4-22.9-78.5c62.1-47.4 109.5-109.5 109.5-179.8z m-351.5-39.2c-14.7 0-31.1-14.7-31.1-31.1 0-14.7 16.3-31.1 31.1-31.1 22.9 0 39.2 16.3 39.2 31.1 0 16.4-14.7 31.1-39.2 31.1z m178-7.6c-14.8 0-31.3-14.6-31.3-30.7 0-14.6 16.5-30.7 31.3-30.7 23.1 0 39.5 16.2 39.5 30.7 0 16.2-16.4 30.7-39.5 30.7z" fill="#24DB5A" p-id="10615"></path></svg>',
          },
          link: 'http://123.56.189.126:8888/scroll-kings-notes/wx',
        },
        {
          icon: { svg: '<svg t="1708159621014" class="icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="8757" width="200" height="200"><path d="M512 1024C229.222 1024 0 794.778 0 512S229.222 0 512 0s512 229.222 512 512-229.222 512-512 512z m259.149-568.883h-290.74a25.293 25.293 0 0 0-25.292 25.293l-0.026 63.206c0 13.952 11.315 25.293 25.267 25.293h177.024c13.978 0 25.293 11.315 25.293 25.267v12.646a75.853 75.853 0 0 1-75.853 75.853h-240.23a25.293 25.293 0 0 1-25.267-25.293V417.203a75.853 75.853 0 0 1 75.827-75.853h353.946a25.293 25.293 0 0 0 25.267-25.292l0.077-63.207a25.293 25.293 0 0 0-25.268-25.293H417.152a189.62 189.62 0 0 0-189.62 189.645V771.15c0 13.977 11.316 25.293 25.294 25.293h372.94a170.65 170.65 0 0 0 170.65-170.65V480.384a25.293 25.293 0 0 0-25.293-25.267z" fill="#C71D23" p-id="8758"></path></svg>' },
          link: 'https://gitee.com/youpingshuo',
        },
        {
          icon: 'github',
          link: 'https://github.com/ypsyyds666',
        },
      ],
    },
    // pwa 配置
    pwa: {
      outDir: '.vitepress/dist', // 输出目录
      registerType: 'autoUpdate', // 注册类型为自动更新
      manifest: {
        id: 'yps-wsy', // 清单 ID
        name: 'wsy', // 应用名称
        short_name: 'wsy', // 应用的短名称
        description: 'wsy by YPS', // 应用的描述
        theme_color: '#ffffff', // 主题颜色
        background_color: '#ffffff',
        display: 'standalone',
        icons: [
          {
            src: '/wsy.png', // 图标路径
            sizes: '192x192', // 图标尺寸
            type: 'image/png', // 图标类型
          },
          {
            src: '/wsy.png',
            sizes: '512x512',
            type: 'image/png',
          },
        ],
      },
      workbox: {
        maximumFileSizeToCacheInBytes: 50000000,
        globPatterns: ['**/*.{css,js,html,svg,png,ico,txt,woff2}'], // 匹配需要缓存的文件类型
        runtimeCaching: [
          {
            urlPattern: /^https:\/\/cdn\.jsdelivr\.net\/.*/i, // 匹配需要缓存的 jsdelivr 资源
            handler: 'NetworkFirst', // 网络优先策略
            options: {
              cacheName: 'jsdelivr-cache', // 缓存名称
              expiration: {
                maxEntries: 10, // 最大缓存条目数
                maxAgeSeconds: 60 * 60 * 24 * 7, // 缓存有效期，7天
              },
              cacheableResponse: {
                statuses: [0, 200], // 缓存的响应状态码
              },
            },
          },
        ],
      },
    },
  }),
)
